<?php
namespace app\action\admin;
use core\BaseAction;
use core\App;
use core\JsonInfo;
use core\ParamFilter;
use stdclass;
class MenuAction extends BaseAction{
	//角色列表
	function getList($params,$req,$res){
		return $this->view("admin.menu_list");
	}
	//角色列表数据
	function postList($params){
		$service = App::bean('\\app\\service\\admin\\MenuService');
		$id = $params["id"];
		$name = $params["name"];
		$list = $service->findMenusByParentId($id,$name);
		$this->json($list);
	}
	
	function postCreate($params){
		$menus = $params['menus'];
		$service = App::bean('\\app\\service\\admin\\MenuService');
		$service->autoLoadMunus($menus);
		$info = new JsonInfo();
		$info->success = true;
		$info->msg = '菜单更新成功！';
		$this->json($info);
	}
	
	function postModifyMenuRole($params){
		$info = new JsonInfo();
		if(empty($params['menuIds'])||empty($params['roleIds'])){
			$info->msg = "非法数据";
		}else{
			$service = App::bean('\\app\\service\\admin\\MenuService');
			$service->updateMenuRole($params['menuIds'],$params['roleIds'],$info);
		}
		return $this->json($info);
	}
	
	
	//菜单授权列表
	function getRoleMenuList($params){
		return $this->view("admin.role_menu_list");
	}
	//菜单授权数据
	function postRoleMenuList($params){
		//初始化查询过滤器
		$filter = new ParamFilter($params);
		//调用业务逻辑
		$service = App::bean('\\app\\service\\admin\\MenuService');
		$service->queryAuthMenuByFilter($filter);
		$this->json($filter->grid);
	}
	
	//删除授权角色
	function postDelRoleMenu($params){
		$info = new JsonInfo();
		if(empty($params['Q_id_in'])){
			$info->msg = "非法数据";
		}else{
			$service = App::bean('\\app\\service\\admin\\MenuService');
			$filter = new ParamFilter($params);
			$info = $service->delRoleMenuByFilter($filter);
		}
		return $this->json($info);
	}
	
}